<template>
	<view class="icons" @click.stop="likeTap">
		<uni-icons
			size="20"
			color="#e1e0c7"
			:type="like ? 'heart-filled' : 'heart'"
		></uni-icons>
	</view>
</template>

<script>
	export default {
		props:{
			item: {
				type: Object,
				default() {
					return {}
				}
			}
		},
		watch: {
			item(newVal) {
				this.like = this.item.is_like
			}
		},
		created() {
			this.like = this.item.is_like
		},
		data() {
			return {
				like: false
			};
		},
		methods:{
			likeTap() {
				this.like = !this.like
				this.setUpdateLikes()
				console.log('like')
			},
			setUpdateLikes() {
				uni.showLoading()
				this.$api.update_like({
					user_id: '5f1fcb0f4a35ab0001a73875',
					article_id: this.item._id
				}).then((res) => {
					
					uni.showLoading({
						title: this.like ? '收藏成功' : '取消收藏',
						icon: 'none'
					})
					uni.hideLoading()
					console.log('update_likes', res)
				})
			}
		}
	}
</script>

<style>
.icons {
	position: absolute;
	right: 0;
	top: 0;
	display: flex;
	justify-content: center;
	align-items: center;
	width: 20px;
	height: 20px;
}
</style>
